<div class="ransack-advanced-search">

  <div class="row">
  <% if RansackAdvancedSearch.enable_saved_searches %>
    <div class="col-md-4">
      <%= render 'ransack_advanced_search/saved_searches_list', redirect_path: redirect_path %>
    </div>
    <div class="col-md-8">
  <% else %>
    <div class="col-md-12">
  <% end %>
      <%= search_form_for(@search, url: search_url, html: { method: :post, class: 'form-inline', role: 'form'  }) do |f| %>
        <% setup_search_form f, @search %>

        <% if RansackAdvancedSearch.enable_saved_searches %>
          <div class="form-group">
            <%= label_tag 'Descrição da Busca (necessária para salvar a busca)' %>
            <%= text_field_tag :description, @saved_search.try(:description), class: 'form-control input-sm' %>
            <% if @saved_search %>
              <%= hidden_field_tag :saved_search, @saved_search.id %>
              <%= hidden_field_tag :use_search_params, true %>
            <% end %>
          </div>
        <% end %>

        <h4><%= t('ransack.quick_search.condition_group.title') %></h4>
        <div class="form-group">
          <% if f.grouping_fields.empty? %>
            <%= render partial: 'ransack_advanced_search/grouping_fields',
                       locals: { f: f, remove_able: false } %>
          <% else %>
            <%= f.grouping_fields do |g| %>
              <%= render partial: 'ransack_advanced_search/grouping_fields',
                         locals: { f: f, remove_able: true } %>
            <% end %>
            <%= button_to_add_fields '', f, :grouping %>
          <% end %>
        </div>

        <div class="clearfix"></div>
        <div class="ransack-action-buttons">
          <%= f.submit t('ransack.advanced_search.form.submit_text'), class: 'btn btn-primary' %>
          <% if RansackAdvancedSearch.enable_saved_searches %>
            <%= f.submit t('ransack.advanced_search.form.save_submit_text'), name: 'save_search', class: 'btn btn-primary' %>
            <%= f.submit t('ransack.advanced_search.form.save_new_submit_text'), name: 'save_new_search', class: 'btn btn-primary' %>
          <% end %>
          <%= link_to t('ransack.advanced_search.form.clear_search_text'), redirect_path, class: 'btn btn-default' %>
        </div>
      <% end %>
    </div>
  </div>
</div>

<% content_for(:ransack_advanced_search_setup) do %>
  <%= stylesheet_link_tag 'ransack_advanced_search/application', media: 'all' %>
  <%= javascript_include_tag 'ransack_advanced_search/application' %>

  <script>
    $(document).ready(function () {
      <%= yield(:ransack_setup) %>
    });
  </script>
<% end %>
